package com.dinstar.dinlink.utils;

import android.content.Context;

import com.orhanobut.hawk.Hawk;

public class Cacher {

    public static void init(Context context) {
        Hawk.init(context).build();
    }


    public static void set(String key, Object obj) {
        try {
            if (obj != null) {
                Hawk.put(key, obj);
            } else {
                Hawk.delete(key);
            }
        } catch (Exception e) {
        }
    }


    public static <T> T get(String key) {
        try {
            T obj = Hawk.get(key);
            return obj;
        } catch (Exception e) {
            return null;
        }
    }

    public static <T> T get(String key, T defaultValue) {
        T value = get(key);
        if (value == null) {
            value = defaultValue;
        }
        return value;
    }

    public static String getString(String key) {
        try {
            String str = Hawk.get(key);
            return str;
        } catch (Exception e) {
            return null;
        }
    }

    public static void clear() {
        try {
            Hawk.deleteAll();
        } catch (Exception e) {
        }
    }
}
